package www.wen.com.common.lib.view.popuview

import android.content.Context
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isGone
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import www.wen.com.common.R
import www.wen.com.common.lib.extension.getColorAgency
import www.wen.com.common.lib.helper.DismissCallBack


/**
 * @author WEN
 * @Description: 结果提示窗口
 * @date 2021/10/25 16:49
 */
class TipPopupView(
    context: Context,
    private val resId: Int = R.drawable.svg_fail_remind,
    private val title: String = "",
    private val titleColor: Int = R.color.color1A1A1A,
    private val message: String = "",
    private val messageColor: Int = R.color.color666666,
    private val dismissCallBack: DismissCallBack? = null,
) : CenterPopupView(context) {

    lateinit var mIvStatus: ImageView

    lateinit var mTvTitle: TextView

    lateinit var mTvMessage: TextView

    override fun getImplLayoutId(): Int = R.layout.popupview_tip

    override fun onCreate() {
        super.onCreate()
        mIvStatus = findViewById(R.id.ivStatus)
        mTvTitle = findViewById(R.id.strStatus)
        mTvMessage = findViewById(R.id.message)

        mIvStatus.setImageResource(resId)
        mTvTitle.text = title
        mTvMessage.text = message

        mTvTitle.isGone = title.isEmpty()

        mTvTitle.setTextColor(getColorAgency(titleColor))
        mTvMessage.setTextColor(getColorAgency(messageColor))
    }

    override fun getMaxWidth(): Int {
        return (XPopupUtils.getScreenWidth(context) * 0.7f).toInt()
    }

    override fun onDismiss() {
        super.onDismiss()
        dismissCallBack?.invoke()
    }

}